﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AF_Web
{
    public class ImageHelper
    {
        public bool Base64StringToImage(string base64String, string saveToPath)
        {
            bool result = false;
            try
            {
                Regex Reg = new Regex("data:image/.*?;base64,");
                string dataString = Reg.Replace(base64String, "").Replace(" ","+");
                MemoryStream stream = new MemoryStream(Convert.FromBase64String(dataString));
                Bitmap img = new Bitmap(stream);
                img.Save(saveToPath);
                stream.Dispose();
                result = true;
            }
            catch (Exception)
            {
                result = false;
            }
            return result;
        }
    }
}
